macro(COPY_FILE_IF_CHANGED IN_FILE OUT_DIR PROJECT)
    #message("Arg0=${ARGV0} Arg1=${ARGV1} Arg2=${ARGV2} Arg3=${ARGV3}")
    set(SUFFIX ${ARGV3})

    if(NOT DEFINED SUFFIX)
        set(TARGET ${PROJECT}-EXPORT)
    else()
        set(TARGET ${PROJECT}-${SUFFIX})
    endif()

    if(NOT TARGET ${TARGET})
        message("Create Custom target:${TARGET}")
        add_custom_target(${TARGET} ALL COMMENT "Exporting file ${IN_FILE} into build tree ${OUT_DIR} by ${TARGET}")
    endif()

    get_filename_component(FILENAME "${IN_FILE}" NAME)
    add_custom_command(TARGET ${TARGET} COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/${IN_FILE}" "${OUT_DIR}/${FILENAME}")
    install(FILES "${IN_FILE}" COMPONENT ${PROJECT} DESTINATION .)
endmacro()

macro(copy_files GLOBPAT DESTINATION target)
  file(GLOB COPY_FILES
    RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
    ${GLOBPAT})
  add_custom_target(${target} ALL
    COMMENT "Copying files: ${GLOBPAT}")

  foreach(FILENAME ${COPY_FILES})
    set(SRC "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}")
    set(DST "${DESTINATION}/${FILENAME}")

    add_custom_command(
      TARGET ${target}
      COMMAND ${CMAKE_COMMAND} -E copy ${SRC} ${DST}
      )
  endforeach(FILENAME)
endmacro(copy_files)

macro(configure_files srcDir destDir)
    message(STATUS "Configuring directory ${destDir}")
    make_directory(${destDir})

    file(GLOB templateFiles RELATIVE ${srcDir} ${srcDir}/*)
    foreach(templateFile ${templateFiles})
        set(srcTemplatePath ${srcDir}/${templateFile})
        if(NOT IS_DIRECTORY ${srcTemplatePath})
            message(STATUS "Configuring file ${templateFile}")
            configure_file(
                    ${srcTemplatePath}
                    ${destDir}/${templateFile}
                    @ONLY)
        endif(NOT IS_DIRECTORY ${srcTemplatePath})
    endforeach(templateFile)
endmacro(configure_files)
